﻿Public Class RunidInmobiliarias

    Public Shared Function SeleccionarTodo(ByVal descEmpresa As String, ByVal DisplaySelect As Boolean, ByVal pUnidInmobiliaria As EunidInmobiliarias) As List(Of EunidInmobiliarias)
        Dim unidadesInmb As List(Of EunidInmobiliarias) = Nothing

        Dim options As New TransactionOptions
        options.IsolationLevel = Transactions.IsolationLevel.ReadCommitted
        options.Timeout = New TimeSpan(0, 2, 0)

        Using scope As New TransactionScope(TransactionScopeOption.Required, options)
            Try
                unidadesInmb = DunidInmobiliarias.SeleccionarTodo(descEmpresa, pUnidInmobiliaria)
                If unidadesInmb Is Nothing Then unidadesInmb = New List(Of EunidInmobiliarias)
                If DisplaySelect Then unidadesInmb.Insert(0, New EunidInmobiliarias("00", "-- SELECCIONAR --"))
                scope.Complete()
            Catch ex As Exception
                Throw
            End Try
        End Using

        Return unidadesInmb
    End Function
    Public Shared Function SeleccionarXEstado(ByVal descEmpresa As String, ByVal DisplaySelect As Boolean, ByVal idProyecto As Int32, ByVal idEtapa As Int32) As List(Of EunidInmobiliarias)
        Dim unidadesInmb As List(Of EunidInmobiliarias) = Nothing

        Dim options As New TransactionOptions
        options.IsolationLevel = Transactions.IsolationLevel.ReadCommitted
        options.Timeout = New TimeSpan(0, 2, 0)

        Using scope As New TransactionScope(TransactionScopeOption.Required, options)
            Try
                unidadesInmb = DunidInmobiliarias.SeleccionarXEstado(descEmpresa, idProyecto, idEtapa)
                If unidadesInmb Is Nothing Then unidadesInmb = New List(Of EunidInmobiliarias)
                If DisplaySelect Then unidadesInmb.Insert(0, New EunidInmobiliarias("00", "-- SELECCIONAR --"))
                scope.Complete()
            Catch ex As Exception
                Throw
            End Try
        End Using

        Return unidadesInmb
    End Function

    Public Shared Function consultaInmuebleXtpo(ByVal descEmpresa As String, ByVal pUnidInmobiliaria As EunidInmobiliarias) As Int32
        Dim cantidad As Int32 = 0

        Dim options As New TransactionOptions
        options.IsolationLevel = Transactions.IsolationLevel.ReadCommitted
        options.Timeout = New TimeSpan(0, 2, 0)

        Using scope As New TransactionScope(TransactionScopeOption.Required, options)
            Try
                cantidad = DunidInmobiliarias.consultaInmuebleXtpo(descEmpresa, pUnidInmobiliaria)
                scope.Complete()
            Catch ex As Exception
                Throw
            End Try
        End Using

        Return cantidad
    End Function

    '-------   MENU CONSULTA STOCK  ------'
    Public Shared Function SeleccionarTodoXAll(ByVal descEmpresa As String, ByVal DisplaySelect As Boolean, ByVal idProyecto As Int32, ByVal idEtapa As Int32) As List(Of EunidInmobiliarias)
        Dim unidadesInmb As List(Of EunidInmobiliarias) = Nothing

        Dim options As New TransactionOptions
        options.IsolationLevel = Transactions.IsolationLevel.ReadCommitted
        options.Timeout = New TimeSpan(0, 2, 0)

        Using scope As New TransactionScope(TransactionScopeOption.Required, options)
            Try
                unidadesInmb = DunidInmobiliarias.SeleccionarTodoXAll(descEmpresa, idProyecto, idEtapa)
                If unidadesInmb Is Nothing Then unidadesInmb = New List(Of EunidInmobiliarias)
                If DisplaySelect Then unidadesInmb.Insert(0, New EunidInmobiliarias("00", "-- SELECCIONAR --"))
                scope.Complete()
            Catch ex As Exception
                Throw
            End Try
        End Using

        Return unidadesInmb
    End Function
    '-------------------------------------'

    Public Shared Function Seleccionar_(ByVal descEmpresa As String, ByVal DisplaySelect As Boolean) As List(Of EunidInmobiliarias)
        Dim unidadesInmb As List(Of EunidInmobiliarias) = Nothing

        Dim options As New TransactionOptions
        options.IsolationLevel = Transactions.IsolationLevel.ReadCommitted
        options.Timeout = New TimeSpan(0, 2, 0)

        Using scope As New TransactionScope(TransactionScopeOption.Required, options)
            Try
                unidadesInmb = DunidInmobiliarias.Seleccionar_(descEmpresa)
                If unidadesInmb Is Nothing Then unidadesInmb = New List(Of EunidInmobiliarias)
                If DisplaySelect Then unidadesInmb.Insert(0, New EunidInmobiliarias("00", "-- SELECCIONAR --"))
                scope.Complete()
            Catch ex As Exception
                Throw
            End Try
        End Using

        Return unidadesInmb
    End Function
    Public Shared Function Añadir(ByVal descEmpresa As String, ByVal pUnidInmobiliaria As EunidInmobiliarias) As Boolean
        Dim resultado As Boolean = False

        Dim options As New TransactionOptions
        options.IsolationLevel = Transactions.IsolationLevel.ReadCommitted
        options.Timeout = New TimeSpan(0, 2, 0)

        Using scope As New TransactionScope(TransactionScopeOption.Required, options)
            Try
                resultado = DunidInmobiliarias.Añadir(descEmpresa, pUnidInmobiliaria)
                scope.Complete()
            Catch ex As Exception
                Throw
            End Try
        End Using

        Return resultado
    End Function
    Public Shared Function Editar(ByVal descEmpresa As String, ByVal pUnidInmobiliaria As EunidInmobiliarias) As Boolean
        Dim resultado As Boolean = False

        Dim options As New TransactionOptions
        options.IsolationLevel = Transactions.IsolationLevel.ReadCommitted
        options.Timeout = New TimeSpan(0, 2, 0)

        Using scope As New TransactionScope(TransactionScopeOption.Required, options)
            Try
                resultado = DunidInmobiliarias.Editar(descEmpresa, pUnidInmobiliaria)
                scope.Complete()
            Catch ex As Exception
                Throw
            End Try
        End Using

        Return resultado
    End Function
    Public Shared Function Eliminar(ByVal descEmpresa As String, ByVal pUnidInmobiliaria As EunidInmobiliarias) As Boolean
        Dim resultado As Boolean = False

        Dim options As New TransactionOptions
        options.IsolationLevel = Transactions.IsolationLevel.ReadCommitted
        options.Timeout = New TimeSpan(0, 2, 0)

        Using scope As New TransactionScope(TransactionScopeOption.Required, options)
            Try
                resultado = DunidInmobiliarias.Eliminar(descEmpresa, pUnidInmobiliaria)
                scope.Complete()
            Catch ex As Exception
                Throw
            End Try
        End Using

        Return resultado
    End Function

    '-------    MENU SEGUIMIENTO    --------'
    Public Shared Function SeleccionarXNroPartida(ByVal descEmpresa As String, ByVal pSeparacionVenta As EseparacionVenta) As List(Of EunidInmobiliarias)
        Dim unidadesInmb As List(Of EunidInmobiliarias) = Nothing

        Dim options As New TransactionOptions
        options.IsolationLevel = Transactions.IsolationLevel.ReadCommitted
        options.Timeout = New TimeSpan(0, 2, 0)

        Using scope As New TransactionScope(TransactionScopeOption.Required, options)
            Try
                unidadesInmb = DunidInmobiliarias.SeleccionarXNroPartida(descEmpresa, pSeparacionVenta)
                If unidadesInmb Is Nothing Then unidadesInmb = New List(Of EunidInmobiliarias)
                scope.Complete()
            Catch ex As Exception
                Throw
            End Try
        End Using

        Return unidadesInmb
    End Function

    '-------   MENU ATENCION CLIENTE  ------'
    Public Shared Function SeleccionarXPosCliente(ByVal descEmpresa As String, ByVal pProforma As EproformaCabecera) As List(Of EunidInmobiliarias)
        Dim unidadesInmb As List(Of EunidInmobiliarias) = Nothing

        Dim options As New TransactionOptions
        options.IsolationLevel = Transactions.IsolationLevel.ReadCommitted
        options.Timeout = New TimeSpan(0, 2, 0)

        Using scope As New TransactionScope(TransactionScopeOption.Required, options)
            Try
                unidadesInmb = DunidInmobiliarias.SeleccionarXPosCliente(descEmpresa, pProforma)
                If unidadesInmb Is Nothing Then unidadesInmb = New List(Of EunidInmobiliarias)
                scope.Complete()
            Catch ex As Exception
                Throw
            End Try
        End Using

        Return unidadesInmb
    End Function
    Public Shared Function SeleccionarXCliente(ByVal descEmpresa As String, ByVal pSeparacionVenta As EseparacionVenta) As List(Of EunidInmobiliarias)
        Dim unidadesInmb As List(Of EunidInmobiliarias) = Nothing

        Dim options As New TransactionOptions
        options.IsolationLevel = Transactions.IsolationLevel.ReadCommitted
        options.Timeout = New TimeSpan(0, 2, 0)

        Using scope As New TransactionScope(TransactionScopeOption.Required, options)
            Try
                unidadesInmb = DunidInmobiliarias.SeleccionarXCliente(descEmpresa, pSeparacionVenta)
                If unidadesInmb Is Nothing Then unidadesInmb = New List(Of EunidInmobiliarias)
                scope.Complete()
            Catch ex As Exception
                Throw
            End Try
        End Using

        Return unidadesInmb
    End Function

    '-------    MENU REPORTE EVOLTA / VERSUS    ------------'
    Public Shared Function SeleccionarXPosClienteXVersus(ByVal descEmpresa As String, ByVal pProforma As EproformaCabecera) As List(Of EunidInmobiliarias)
        Dim unidadesInmb As List(Of EunidInmobiliarias) = Nothing

        Dim options As New TransactionOptions
        options.IsolationLevel = Transactions.IsolationLevel.ReadCommitted
        options.Timeout = New TimeSpan(0, 2, 0)

        Using scope As New TransactionScope(TransactionScopeOption.Required, options)
            Try
                unidadesInmb = DunidInmobiliarias.SeleccionarXPosClienteXVersus(descEmpresa, pProforma)
                If unidadesInmb Is Nothing Then unidadesInmb = New List(Of EunidInmobiliarias)
                scope.Complete()
            Catch ex As Exception
                Throw
            End Try
        End Using

        Return unidadesInmb
    End Function

    '-------   MENU REPORTE DEINMUEBLES POR ETAPA  ------'
    Public Shared Function Reporte_InmueblesXEtapaTodos(ByVal descEmpresa As String, ByVal DisplaySelect As Boolean, ByVal pUnidInmobiliaria As EunidInmobiliarias) As List(Of EunidInmobiliarias)
        Dim inmueblesxEtapas As List(Of EunidInmobiliarias) = Nothing

        Dim options As New TransactionOptions
        options.IsolationLevel = Transactions.IsolationLevel.ReadCommitted
        options.Timeout = New TimeSpan(0, 2, 0)

        Using scope As New TransactionScope(TransactionScopeOption.Required, options)
            Try
                inmueblesxEtapas = DunidInmobiliarias.Reporte_InmueblesXEtapaTodos(descEmpresa, pUnidInmobiliaria)
                If inmueblesxEtapas Is Nothing Then inmueblesxEtapas = New List(Of EunidInmobiliarias)
                scope.Complete()
            Catch ex As Exception
                Throw
            End Try
        End Using

        Return inmueblesxEtapas
    End Function
    Public Shared Function Reporte_InmueblesXEtapaVendidos(ByVal descEmpresa As String, ByVal DisplaySelect As Boolean, ByVal pUnidInmobiliaria As EunidInmobiliarias) As List(Of EunidInmobiliarias)
        Dim inmueblesxEtapas As List(Of EunidInmobiliarias) = Nothing

        Dim options As New TransactionOptions
        options.IsolationLevel = Transactions.IsolationLevel.ReadCommitted
        options.Timeout = New TimeSpan(0, 2, 0)

        Using scope As New TransactionScope(TransactionScopeOption.Required, options)
            Try
                inmueblesxEtapas = DunidInmobiliarias.Reporte_InmueblesXEtapaVendidos(descEmpresa, pUnidInmobiliaria)
                If inmueblesxEtapas Is Nothing Then inmueblesxEtapas = New List(Of EunidInmobiliarias)
                scope.Complete()
            Catch ex As Exception
                Throw
            End Try
        End Using

        Return inmueblesxEtapas
    End Function
    Public Shared Function Reporte_InmueblesXEtapaDisponibles(ByVal descEmpresa As String, ByVal DisplaySelect As Boolean, ByVal pUnidInmobiliaria As EunidInmobiliarias) As List(Of EunidInmobiliarias)
        Dim inmueblesxEtapas As List(Of EunidInmobiliarias) = Nothing

        Dim options As New TransactionOptions
        options.IsolationLevel = Transactions.IsolationLevel.ReadCommitted
        options.Timeout = New TimeSpan(0, 2, 0)

        Using scope As New TransactionScope(TransactionScopeOption.Required, options)
            Try
                inmueblesxEtapas = DunidInmobiliarias.Reporte_InmueblesXEtapaDisponibles(descEmpresa, pUnidInmobiliaria)
                If inmueblesxEtapas Is Nothing Then inmueblesxEtapas = New List(Of EunidInmobiliarias)
                scope.Complete()
            Catch ex As Exception
                Throw
            End Try
        End Using

        Return inmueblesxEtapas
    End Function
    Public Shared Function Reporte_InmueblesXEtapaBloqueados(ByVal descEmpresa As String, ByVal DisplaySelect As Boolean, ByVal pUnidInmobiliaria As EunidInmobiliarias) As List(Of EunidInmobiliarias)
        Dim inmueblesxEtapas As List(Of EunidInmobiliarias) = Nothing

        Dim options As New TransactionOptions
        options.IsolationLevel = Transactions.IsolationLevel.ReadCommitted
        options.Timeout = New TimeSpan(0, 2, 0)

        Using scope As New TransactionScope(TransactionScopeOption.Required, options)
            Try
                inmueblesxEtapas = DunidInmobiliarias.Reporte_InmueblesXEtapaBloqueados(descEmpresa, pUnidInmobiliaria)
                If inmueblesxEtapas Is Nothing Then inmueblesxEtapas = New List(Of EunidInmobiliarias)
                scope.Complete()
            Catch ex As Exception
                Throw
            End Try
        End Using

        Return inmueblesxEtapas
    End Function
    '---------------------------------------'
End Class
